import 'package:flutter/material.dart';
import 'package:luckiness/utils/model/order_info.dart';
import '../utils/general.dart';
import '../components/ffcartnumber.dart';
import '../components/ffpricenumber.dart';
import '../components/ffbottompay.dart';
import '../components/ffguess.dart';
// import 'package:pull_to_refresh/pull_to_refresh.dart';
// import 'package:flutter/cupertino.dart';

class Cart extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return CartState();
  }

}

class CartState extends State<Cart> {

  double price = 21;

  Widget emptyCartWidget() {
    double scale = widthScale(context);
    Container con = Container(
      width: screenWidth(context),
      height: screenHeight(context) - bottomTabBarHeight(context) - statusBarHeight(context) - 50,
      color: separatorLineColor,
      child: Column(
        mainAxisSize:MainAxisSize.min,
        children:[
          Container(
            width:90 * scale,
            height:120 * scale,
            padding:EdgeInsets.only(top:0 * scale),
            child:Image.asset('assets/images/shopping_cart_null.png', fit:BoxFit.fill),
          ),
          Padding(
            padding: EdgeInsets.symmetric(vertical:20 * scale),
            child: Text(
              '空空如也',
              style:TextStyle(color:Color.fromRGBO(166, 166, 166, 1.0), fontWeight:FontWeight.normal, fontSize:13 * scale, decoration: TextDecoration.none)
            ),
          ),
          Padding(
            padding: EdgeInsets.symmetric(vertical:10 * scale),
            child: GestureDetector(
              onTap:(){
                print('浪');
              },
              child:Container(
                width: 100 * scale,
                height: 30 * scale,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(4 * scale),
                  border: Border.all(color:Color.fromRGBO(144, 192, 239, 1.0)),
                ),
                child: Center(
                  child: Text(
                    '去喝一杯',
                    style:TextStyle(fontSize:14 * scale, fontWeight:FontWeight.normal, color:Color.fromRGBO(144, 192, 239, 1.0)),
                  ),
                ),
              ),
            ),
          )
          
        ],
      ),
    );
    return con;
  }

  Widget cartCell(OrderInfo info) {
    double scale = widthScale(context);
    GlobalKey<FFCartNumberState> cartNumberState = GlobalKey<FFCartNumberState>();
    GlobalKey<FFPriceState> priceState = GlobalKey<FFPriceState>();
    return Padding(
      padding: EdgeInsets.all(15 * scale),
      child: Row(
        mainAxisAlignment:MainAxisAlignment.spaceBetween,
        children:[
          GestureDetector(
            onTap:(){},
            child:Icon(Icons.check_circle, size:24 * scale, color:Color.fromRGBO(136, 175, 213, 1.0)),
          ),
          Expanded(
            child: Row(
              mainAxisAlignment:MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Column(
                  mainAxisSize: MainAxisSize.min,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children:[
                    Row(
                      children: <Widget>[
                        Text('标准美式', style:TextStyle(fontSize: 15 * scale, color:Colors.black87)),
                        Container(
                          width: 34 * scale,
                          height: 16 * scale,
                          decoration:BoxDecoration(
                            borderRadius: BorderRadius.circular(2),
                            color:Color.fromRGBO(255, 129, 2, 1.0),                            
                          ),
                          child: Center(
                            child:Text(
                              '充二赠一',
                              style:TextStyle(fontSize: 8,color:Colors.white, fontWeight:FontWeight.normal),
                            ),
                          ),
                        )
                      ],
                    ),
                    Text(
                      '大/单份奶/单份糖/热',
                      style:TextStyle(fontSize:10 * scale, fontWeight:FontWeight.normal, color:Color.fromRGBO(80, 80, 80, 1.0)),
                    ),
                    Text(
                      '仅限打包带走',
                      textAlign: TextAlign.start,
                      style:TextStyle(fontSize:10 * scale, fontWeight:FontWeight.normal, color:Color.fromRGBO(85, 122, 157, 1.0)),
                    ),
                  ],
                ),
                FFPrice(key:priceState),
              ],
            )
          ),
          FFCartNumber(key:cartNumberState, onPress:(){
            priceState.currentState.ffUpdatePrice(21.0 * cartNumberState.currentState.number);
          }),
        ]
      ),
    );
  }

  Widget judgeInfo() {
    double scale = widthScale(context);
    if (FFShareInstance.order == null) {
      return emptyCartWidget();
    }else {
      GlobalKey<FFBottomPayState> ffBottomPayState = GlobalKey<FFBottomPayState>();
      return SingleChildScrollView(
        child:Column(
          mainAxisSize: MainAxisSize.min,

          children:[
            SizedBox(
              height:68 * scale,
              child: Image.asset('assets/images/order/order1.png', fit:BoxFit.fill),
            ),
            cartCell(FFShareInstance.order),
            Container(
              height: screenHeight(context) - statusBarHeight(context) - 50 - bottomTabBarHeight(context) - 210 * scale,
              width: screenWidth(context),
              color: Colors.grey[100],
              child:FFGuess(),
            ),
            FFBottomPay(key: ffBottomPayState,),
          ],
        ),
      );
        // child: cartCell(FFShareInstance.order),);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar:AppBar(
        title:Text('购物车', style:TextStyle(fontSize:18 * widthScale(context), color:Colors.black87)),
        backgroundColor: Colors.white,
      ),
      body: judgeInfo(),
    );
  }

}

// class CartState extends State<Cart> {
//  List<String> items = ["1", "2", "3", "4", "5", "6", "7", "8"];
//   RefreshController _refreshController =
//       RefreshController(initialRefresh: false);

//   void _onRefresh() async{
//     // monitor network fetch
//     await Future.delayed(Duration(milliseconds: 1000));
//     // if failed,use refreshFailed()
//     _refreshController.refreshCompleted();
//   }

//   void _onLoading() async{
//     // monitor network fetch
//     await Future.delayed(Duration(milliseconds: 1000));
//     // if failed,use loadFailed(),if no data return,use LoadNodata()
//     items.add((items.length+1).toString());
//     if(mounted)
//     setState(() {

//     });
//     _refreshController.loadComplete();
//   }

//   @override
//   Widget build(BuildContext context) {
//     return Scaffold(
//       body: SmartRefresher(
//         enablePullDown: true,
//         enablePullUp: true,
//         header: WaterDropHeader(),
//         footer: CustomFooter(
//           builder: (BuildContext context,LoadStatus mode){
//             Widget body ;
//             if(mode==LoadStatus.idle){
//               body =  Text("pull up load");
//             }
//             else if(mode==LoadStatus.loading){
//               body =  CupertinoActivityIndicator();
//             }
//             else if(mode == LoadStatus.failed){
//               body = Text("Load Failed!Click retry!");
//             }
//             else if(mode == LoadStatus.canLoading){
//                 body = Text("release to load more");
//             }
//             else{
//               body = Text("No more Data");
//             }
//             return Container(
//               height: 55.0,
//               child: Center(child:body),
//             );
//           },
//         ),
//         controller: _refreshController,
//         onRefresh: _onRefresh,
//         onLoading: _onLoading,
//         child: ListView.builder(
//           itemBuilder: (c, i) => Card(child: Center(child: Text(items[i]))),
//           itemExtent: 100.0,
//           itemCount: items.length,
//         ),
//       ),
//     );
//   }
//   }